{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"https://raw.githubusercontent.com/Qiskit/qiskit-tutorials/master/images/qiskit-heading.png\" alt=\"Note: In order for images to show up in this jupyter notebook you need to select File => Trusted Notebook\" width=\"500 px\" align=\"left\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## _*Let's Make a Deal*_ \n",
    "\n",
    "The latest version of this notebook is available on https://github.com/qiskit/qiskit-tutorial.\n",
    "\n",
    "For more information about how to use the IBM Q experience (QX), consult the [tutorials](https://quantumexperience.ng.bluemix.net/qstage/#/tutorial?sectionId=c59b3710b928891a1420190148a72cce&pageIndex=0), or check out the [community](https://quantumexperience.ng.bluemix.net/qstage/#/community).\n",
    "\n",
    "***\n",
    "## Contributors\n",
    "\n",
    "Pierre Decoodt, Université Libre de Bruxelles"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\decpi\\Anaconda3\\envs\\q7env\\lib\\site-packages\\marshmallow\\schema.py:364: ChangedInMarshmallow3Warning: strict=False is not recommended. In marshmallow 3.0, schemas will always be strict. See https://marshmallow.readthedocs.io/en/latest/upgrading.html#schemas-are-always-strict\n",
      "  ChangedInMarshmallow3Warning\n"
     ]
    }
   ],
   "source": [
    "# useful additional packages \n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "import numpy as np\n",
    "import time\n",
    "from pprint import pprint\n",
    "\n",
    "# importing Qiskit\n",
    "from qiskit import Aer, IBMQ \n",
    "from qiskit.providers.ibmq import least_busy \n",
    "from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute\n",
    "\n",
    "# import basic plot tools\n",
    "from qiskit.tools.visualization import plot_histogram"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "IBMQ.load_account()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Introduction\n",
    "The Monty Hall problem, named after the original host of the television show \"Let's Make a Deal\" is well known. The game master asks the player to designate between three doors the one behind which a valuable prize has been hidden, such as a luxury car. Goats are hidden behind the other two doors. When the player has issued a preference, the game master opens one of the two remaining doors and one of the goats appears. The player then has the opportunity to choose the closed door remaining instead of the door chosen in first intention.\n",
    "\n",
    "Is it wise, indifferent or unwise to stick with one's first choice, whatever it may have been? Much has been written on about the optimal strategy because the actual solution is counter-intuitive.\n",
    "\n",
    "This tutorial is not intended to illustrate one of the many quantum models proposed on this subject and including many variations. It simply describes a model of the original game that can be played many times by players to convince them of the validity of the optimal strategic solution. This kind of simulation was proposed using conventional hardware, like a shell game, a card deck or a programmed pseudo random number generator.\n",
    "\n",
    "The present game uses the $ |W_{3} \\rangle$ creator circuit described in the tutorial \"W State 1 : Multi-qubit systems\" as a _*true*_$^1$ random number generator.\n",
    "\n",
    "The following state is created and measured: $ |W_{3} \\rangle = \\frac{1}{\\sqrt{3}} \\: (|1 0 0 \\rangle \\: +  |0 1 0 \\rangle\\: +  |0 0 1\\rangle) $\n",
    "\n",
    "Each of the three qubits used represents one of the doors. The car is hidden behind the one corresponding to the qubit measured as 1 (excited) during the measurement.\n",
    "\n",
    "With the help of Hadamard gates, a second true random number generator uses the two-qubit state:\n",
    "\n",
    "$$ H^{\\otimes 2}|0_{a}0_{b}\\rangle=|+_{a}\\rangle \\:|+_{b}\\rangle=\\frac{|0_{a}\\rangle|0_{b}\\rangle+|0_{a}\\rangle|1_{b}\\rangle+|1_{a}\\rangle|0_{b}\\rangle+|1_{a}\\rangle|1_{b}\\rangle}{2}$$\n",
    "\n",
    "From the binary value of the measurement $c_{a} c_{b}$, the following quantity represents the result of a coin flipping:\n",
    "$c_{a} \\oplus c_{b}$. This two-qubit model of true$^1$ random generator was chosen because bias is minimized on the real device.\n",
    "\n",
    "This result is used to determine which of the two doors hiding a goat is opened each time the player has chosen the door that hides the car. This phase is obviously not necessary when the player has chosen a door hiding a goat: the game master can not open the door hiding a car, nor the door chosen by the player$^2$.\n",
    "\n",
    "$^1$ If used on the simulator, it remains a pseudo random number generator.\n",
    "\n",
    "$^2$ This is a hint for finding the optimal strategy: how many times on average is the game master exempt from tossing a coin?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## It's time to play!\n",
    "You may have noticed that the optimal solution has not been hitherto explicitly given. Chances are you already know the answer, and what follows will only comfort you in your belief. For those who are not familiar with this problem, the suspense is preserved and for those who still doubt, this is an opportunity to review your opinion. Play the game a sufficient number of times. Even if you only rely on your intuition for each game, you can use your own success statistics to figure out what is the best strategy. \n",
    "\n",
    "You will first be asked to choose between the simulator (a good choice to start) or a real device."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Your choice for the backend is:  qasm_simulator flag_qx2 is:  True\n"
     ]
    }
   ],
   "source": [
    "\"Choice of the backend\"\n",
    "# local qasm simulator\n",
    "backend = Aer.get_backend('qasm_simulator')\n",
    "\n",
    "# The flag_qx2 must be \"True\" for using the ibmqx2. \n",
    "# \"True\" is also better when using the simulator\n",
    "\n",
    "# Use the IBM Quantum Experience\n",
    "#backend = least_busy(IBMQ.backends(filters=lambda x: not x.configuration().simulator)) #\n",
    "\n",
    "flag_qx2 = True\n",
    "if backend == 'ibmqx4':\n",
    "        flag_qx2 = False\n",
    "        \n",
    "print(\"Your choice for the backend is: \", backend.name(), \"flag_qx2 is: \", flag_qx2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Here, two useful routine\n",
    "# Define a F_gate\n",
    "def F_gate(circ,q,i,j,n,k) :\n",
    "    theta = np.arccos(np.sqrt(1/(n-k+1)))\n",
    "    circ.ry(-theta,q[j])       \n",
    "    circ.cz(q[i],q[j])\n",
    "    circ.ry(theta,q[j])\n",
    "    circ.barrier(q[i])\n",
    "# Define the cxrv gate which uses reverse CNOT instead of CNOT\n",
    "def  cxrv(circ,q,i,j) :\n",
    "    circ.h(q[i])\n",
    "    circ.h(q[j])\n",
    "    circ.cx(q[j],q[i])\n",
    "    circ.h(q[i])\n",
    "    circ.h(q[j])\n",
    "    circ.barrier(q[i],q[j])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 3-qubit W state\n",
    "q = QuantumRegister(5) \n",
    "c = ClassicalRegister(5)\n",
    "W_states = QuantumCircuit(q,c) \n",
    "        \n",
    "W_states.x(q[2]) #start is |100>\n",
    "F_gate(W_states,q,2,1,3,1) # Applying F12\n",
    "F_gate(W_states,q,1,0,3,2) # Applying F23\n",
    "\n",
    "if flag_qx2 : # option ibmqx2 \n",
    "    W_states.cx(q[1],q[2]) # cNOT 21\n",
    "    W_states.cx(q[0],q[1]) # cNOT 32\n",
    "    \n",
    "else :        # option ibmqx4  \n",
    "    cxrv(W_states,q,1,2)\n",
    "    cxrv(W_states,q,0,1)\n",
    "    \n",
    "# Coin tossing\n",
    "W_states.h(q[3]) \n",
    "W_states.h(q[4])\n",
    "\n",
    "for i in range(5) :\n",
    "    W_states.measure(q[i] , c[i]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"Dotted alphabet\"\n",
    "top_bottom = \"███████████████\"\n",
    "blank = \"█             █\"\n",
    "chosen = []\n",
    "chosen = chosen + [\"███████████████\"]\n",
    "chosen = chosen + [\"███████████  ██\"]\n",
    "chosen = chosen + [\"██████████  ███\"]\n",
    "chosen = chosen + [\"█████████  ████\"]\n",
    "chosen = chosen + [\"████████  █████\"]\n",
    "chosen = chosen + [\"█  ████  ██████\"]\n",
    "chosen = chosen + [\"██  ██  ███████\"]\n",
    "chosen = chosen + [\"███    ████████\"]\n",
    "chosen = chosen + [\"████  █████████\"]\n",
    "chosen = chosen + [\"███████████████\"]\n",
    "\n",
    "here_left = []\n",
    "here_left = here_left + [\"███████████████\"]\n",
    "here_left = here_left + [\"███████████████\"]\n",
    "here_left = here_left + [\"███   █████████\"]\n",
    "here_left = here_left + [\"███   █████████\"]\n",
    "here_left = here_left + [\"███   █████████\"]\n",
    "here_left = here_left + [\"███   █████████\"]\n",
    "here_left = here_left + [\"███   █████████\"]\n",
    "here_left = here_left + [\"███        ████\"]\n",
    "here_left = here_left + [\"███████████████\"]\n",
    "here_left = here_left + [\"███████████████\"]\n",
    "here_center = []\n",
    "here_center = here_center + [\"███████████████\"]\n",
    "here_center = here_center + [\"███████████████\"]\n",
    "here_center = here_center + [\"█████      ████\"]\n",
    "here_center = here_center + [\"███   █████████\"]\n",
    "here_center = here_center + [\"███   █████████\"]\n",
    "here_center = here_center + [\"███   █████████\"]\n",
    "here_center = here_center + [\"███   █████████\"]\n",
    "here_center = here_center + [\"█████      ████\"]\n",
    "here_center = here_center + [\"███████████████\"]\n",
    "here_center = here_center + [\"███████████████\"]\n",
    "here_right = []\n",
    "here_right = here_right + [\"███████████████\"]\n",
    "here_right = here_right + [\"███████████████\"]\n",
    "here_right = here_right + [\"███       █████\"]\n",
    "here_right = here_right + [\"███   ███   ███\"]\n",
    "here_right = here_right + [\"███   ███   ███\"]\n",
    "here_right = here_right + [\"███       █████\"]\n",
    "here_right = here_right + [\"███   ██   ████\"]\n",
    "here_right = here_right + [\"███   ███   ███\"]\n",
    "here_right = here_right + [\"███████████████\"]\n",
    "here_right = here_right + [\"███████████████\"]\n",
    "\n",
    "goa=[\"█             █\",\"█   (     )   █\",\"█    (   )    █\",\"█  / O   O \\  █\",\"█     )|(     █\",\"█      @      █\",\"█      =      █\",\"█      Y      █\",\"█             █\"]\n",
    "car=[\"█             █\",\"█   _______   █\",\"█  /       \\  █\",\"█ ° _______ ° █\",\"█  /       \\  █\",\"█ (O) ### (O) █\",\"█  =+=====+=  █\",\"█  ||     ||  █\",\"█             █\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"(RE)INITIATES STATISTICS\"\n",
    "nb_randomnb = 0\n",
    "nb_left =  0\n",
    "nb_center =  0\n",
    "nb_right =  0\n",
    "nb_switches = 0\n",
    "nb_stays = 0\n",
    "nb_won_switching = 0\n",
    "nb_won_sticking = 0\n",
    "nb_games = 0\n",
    "n_won = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "███████████████   ███████████████   ███████████████\n",
      "███████████████   ███████████████   ███████████████\n",
      "███████████████   ███████████████   ███████████████\n",
      "███   █████████   █████      ████   ███       █████\n",
      "███   █████████   ███   █████████   ███   ███   ███\n",
      "███   █████████   ███   █████████   ███   ███   ███\n",
      "███   █████████   ███   █████████   ███       █████\n",
      "███   █████████   ███   █████████   ███   ██   ████\n",
      "███        ████   █████      ████   ███   ███   ███\n",
      "███████████████   ███████████████   ███████████████\n",
      "███████████████   ███████████████   ███████████████ \n",
      "\n",
      "Game master: Your choice? letter l: left door, c: central door, r: right door + enter\n",
      "l\n",
      "Game master:   Your choice was the left door\n",
      "███████████████   ███████████████   ███████████████\n",
      "███████████████   ███████████████   █             █\n",
      "███████████  ██   ███████████████   █   (     )   █\n",
      "██████████  ███   █████      ████   █    (   )    █\n",
      "█████████  ████   ███   █████████   █  / O   O \\  █\n",
      "████████  █████   ███   █████████   █     )|(     █\n",
      "█  ████  ██████   ███   █████████   █      @      █\n",
      "██  ██  ███████   ███   █████████   █      =      █\n",
      "███    ████████   █████      ████   █      Y      █\n",
      "████  █████████   ███████████████   █             █\n",
      "███████████████   ███████████████   ███████████████ \n",
      "\n",
      "I opened the right door and you see a goat\n",
      "You get now an opportunity to change your choice!\n",
      "Do you want to switch for the  central  door?\n",
      "    Answer by (y/n) + enter\n",
      "y\n",
      "███████████████   ███████████████   ███████████████\n",
      "███████████████   █             █   █             █\n",
      "███████████  ██   █   (     )   █   █   (     )   █\n",
      "██████████  ███   █    (   )    █   █    (   )    █\n",
      "█████████  ████   █  / O   O \\  █   █  / O   O \\  █\n",
      "████████  █████   █     )|(     █   █     )|(     █\n",
      "█  ████  ██████   █      @      █   █      @      █\n",
      "██  ██  ███████   █      =      █   █      =      █\n",
      "███    ████████   █      Y      █   █      Y      █\n",
      "████  █████████   █             █   █             █\n",
      "███████████████   ███████████████   ███████████████ \n",
      "\n",
      "Game master: You opened the central door and won a goat! Sorry!\n",
      "\n",
      "YOUR STATS\n",
      "nb of games:  1      total nb won: 0      first choice:  left 1  center 0 right 0\n",
      "nb sticking:  0  nb won when sticking:  0 nb switching: 1  nb won when switching: 0\n",
      "Another game?   Answer by (y/n) + enter\n",
      "y\n",
      "███████████████   ███████████████   ███████████████\n",
      "███████████████   ███████████████   ███████████████\n",
      "███████████████   ███████████████   ███████████████\n",
      "███   █████████   █████      ████   ███       █████\n",
      "███   █████████   ███   █████████   ███   ███   ███\n",
      "███   █████████   ███   █████████   ███   ███   ███\n",
      "███   █████████   ███   █████████   ███       █████\n",
      "███   █████████   ███   █████████   ███   ██   ████\n",
      "███        ████   █████      ████   ███   ███   ███\n",
      "███████████████   ███████████████   ███████████████\n",
      "███████████████   ███████████████   ███████████████ \n",
      "\n",
      "Game master: Your choice? letter l: left door, c: central door, r: right door + enter\n",
      "r\n",
      "Game master:   Your choice was the right door\n",
      "███████████████   ███████████████   ███████████████\n",
      "███████████████   █             █   ███████████████\n",
      "███████████████   █   (     )   █   ███████████  ██\n",
      "███   █████████   █    (   )    █   ██████████  ███\n",
      "███   █████████   █  / O   O \\  █   █████████  ████\n",
      "███   █████████   █     )|(     █   ████████  █████\n",
      "███   █████████   █      @      █   █  ████  ██████\n",
      "███   █████████   █      =      █   ██  ██  ███████\n",
      "███        ████   █      Y      █   ███    ████████\n",
      "███████████████   █             █   ████  █████████\n",
      "███████████████   ███████████████   ███████████████ \n",
      "\n",
      "I opened the central door and you see a goat\n",
      "You get now an opportunity to change your choice!\n",
      "Do you want to switch for the  left  door?\n",
      "    Answer by (y/n) + enter\n",
      "y\n",
      "███████████████   ███████████████   ███████████████\n",
      "█             █   █             █   ███████████████\n",
      "█   (     )   █   █   (     )   █   ███████████  ██\n",
      "█    (   )    █   █    (   )    █   ██████████  ███\n",
      "█  / O   O \\  █   █  / O   O \\  █   █████████  ████\n",
      "█     )|(     █   █     )|(     █   ████████  █████\n",
      "█      @      █   █      @      █   █  ████  ██████\n",
      "█      =      █   █      =      █   ██  ██  ███████\n",
      "█      Y      █   █      Y      █   ███    ████████\n",
      "█             █   █             █   ████  █████████\n",
      "███████████████   ███████████████   ███████████████ \n",
      "\n",
      "Game master: You opened the left door and won a goat! Sorry!\n",
      "\n",
      "YOUR STATS\n",
      "nb of games:  2      total nb won: 0      first choice:  left 1  center 0 right 1\n",
      "nb sticking:  0  nb won when sticking:  0 nb switching: 2  nb won when switching: 0\n",
      "Another game?   Answer by (y/n) + enter\n",
      "n\n",
      "Game over\n"
     ]
    }
   ],
   "source": [
    "\"HERE START THE GAME\"\n",
    "\"Hiding the car and the two goats behind the three doors\"\n",
    "Label = [\"left\", \"central\", \"right\"]\n",
    "shots = 1\n",
    "repeat = \"Y\"\n",
    "while repeat == \"Y\":\n",
    "    nb_of_cars = 4\n",
    "    while nb_of_cars != 1:\n",
    "        result = execute(W_states, backend=backend, shots=shots)\n",
    "        c5str = str(result.result().get_counts(W_states))\n",
    "        nb_of_cars = int(c5str[4]) + int(c5str[5]) + int(c5str[6])\n",
    "\n",
    "        #this is for checking results from the real computer:\n",
    "        if nb_of_cars == 0:\n",
    "            print(\"They managed to hide three goats and no car behind the doors! Restarting the hiding process...\")\n",
    "        if nb_of_cars >= 2: \n",
    "            print(\"They managed to hide\", nb_of_cars, \"cars behind the doors! Restarting the hiding process...\")\n",
    "\n",
    "    print(top_bottom,\" \",top_bottom,\" \",top_bottom)\n",
    "    for i in range(9):\n",
    "        print(here_left[i],\" \",here_center[i],\" \",here_right[i])\n",
    "    print(top_bottom,\" \",top_bottom,\" \",top_bottom,\"\\n\")        \n",
    "    door = input(\"Game master: Your choice? letter l: left door, c: central door, r: right door + enter\\n\").upper()\n",
    "    \n",
    "    picl = here_left\n",
    "    picc = here_center\n",
    "    picr = here_right\n",
    "    if (door == \"L\"):\n",
    "        Doorchosen = 1\n",
    "        nb_left =  nb_left + 1\n",
    "        picl = chosen\n",
    "    else:\n",
    "        if (door == \"C\"):\n",
    "            Doorchosen = 2\n",
    "            nb_center =  nb_center + 1\n",
    "            picc=chosen\n",
    "        else:\n",
    "            Doorchosen = 3\n",
    "            nb_right = nb_right + 1\n",
    "            picr = chosen\n",
    "            \n",
    "    print('Game master:   Your choice was the',Label[Doorchosen-1], \"door\")\n",
    "\n",
    "    \"AN OPPORTUNITY TO CHANGE YOUR MIND\"\n",
    "\n",
    "    c5str = str(result.result().get_counts(W_states))\n",
    "\n",
    "    randomnb = (int(c5str[2]) + int(c5str[3])) %2  \n",
    "\n",
    "    if c5str[4] == \"1\":    #car behind left door \n",
    "        Doorwinning = 1        \n",
    "        if Doorchosen == 1:\n",
    "            Dooropen = 2 + randomnb\n",
    "            Doorswitch = 3 - randomnb            \n",
    "        if Doorchosen == 2:\n",
    "            Dooropen = 3\n",
    "            Doorswitch = 1\n",
    "        if Doorchosen == 3:\n",
    "            Dooropen = 2\n",
    "            Doorswitch = 1    \n",
    "\n",
    "    if c5str[5] == \"1\":     #car behind central door \n",
    "        Doorwinning = 2\n",
    "        if Doorchosen == 2:\n",
    "            Dooropen = 1 + 2*randomnb \n",
    "            Doorswitch = 3 - 2*randomnb \n",
    "        if Doorchosen == 1:\n",
    "            Dooropen = 3            \n",
    "            Doorswitch = 2\n",
    "        if Doorchosen == 3:\n",
    "            Dooropen = 1            \n",
    "            Doorswitch = 2\n",
    "\n",
    "    if c5str[6] == \"1\":     #car behind right door \n",
    "        Doorwinning = 3\n",
    "        if Doorchosen == 3:\n",
    "            Dooropen = randomnb + 1\n",
    "            Doorswitch = 2 - randomnb\n",
    "        if Doorchosen == 1:\n",
    "            Dooropen = 2         \n",
    "            Doorswitch = 3\n",
    "        if Doorchosen == 2:\n",
    "            Dooropen = 1            \n",
    "            Doorswitch = 3\n",
    "            \n",
    "    if Dooropen == 1:\n",
    "        picl = goa\n",
    "    if Dooropen == 2:   \n",
    "        picc = goa\n",
    "    if Dooropen == 3:   \n",
    "        picr = goa        \n",
    "    \n",
    "    print(top_bottom,\" \",top_bottom,\" \",top_bottom)\n",
    "    for i in range(9):\n",
    "        print(picl[i],\" \",picc[i],\" \",picr[i])        \n",
    "    print(top_bottom,\" \",top_bottom,\" \",top_bottom,\"\\n\")\n",
    "    print('I opened the', Label[Dooropen-1], 'door and you see a goat')\n",
    "    print('You get now an opportunity to change your choice!')\n",
    "    print(\"Do you want to switch for the \",Label[Doorswitch-1], \" door?\")\n",
    "    I_switch = input(\"    Answer by (y/n) + enter\\n\").upper()\n",
    "\n",
    "    if (I_switch == \"Y\"):\n",
    "        Doorfinal = Doorswitch\n",
    "    else:\n",
    "        Doorfinal = Doorchosen\n",
    "\n",
    "    \"FINAL ANNOUNCE\"\n",
    "    if Doorfinal == Doorwinning:\n",
    "        if Doorfinal == 1:\n",
    "            picl = car\n",
    "        if Doorfinal == 2:   \n",
    "            picc = car\n",
    "        if Doorfinal == 3:   \n",
    "            picr = car \n",
    "        endmessage = 'won the car! Congratulations!'\n",
    "    else:\n",
    "        if Doorfinal == 1:\n",
    "            picl = goa\n",
    "        if Doorfinal == 2:   \n",
    "            picc = goa\n",
    "        if Doorfinal == 3:   \n",
    "            picr = goa\n",
    "        endmessage = 'won a goat! Sorry!'\n",
    "    \n",
    "    print(top_bottom,\" \",top_bottom,\" \",top_bottom)\n",
    "    for i in range(9):\n",
    "        print(picl[i],\" \",picc[i],\" \",picr[i])        \n",
    "    print(top_bottom,\" \",top_bottom,\" \",top_bottom,\"\\n\")\n",
    "    print('Game master: You opened the',Label[Doorfinal-1],'door and', endmessage)\n",
    "   \n",
    "    \"STATISTICS\"\n",
    "    nb_games = nb_games + 1\n",
    "\n",
    "    if Doorfinal == Doorswitch:\n",
    "        nb_switches = nb_switches +1\n",
    "        if c5str[Doorfinal+3] == \"1\":\n",
    "            nb_won_switching = nb_won_switching + 1\n",
    "    else:\n",
    "        nb_stays = nb_stays+1\n",
    "        if c5str[Doorfinal+3] == \"1\":\n",
    "            nb_won_sticking = nb_won_sticking + 1\n",
    "    n_won = nb_won_switching + nb_won_sticking\n",
    "    print()    \n",
    "    print(\"YOUR STATS\")    \n",
    "    print(\"nb of games: \", nb_games,\"     total nb won:\", n_won, \"     first choice:  left\",nb_left,\" center\", nb_center,\"right\", nb_right)\n",
    "    print(\"nb sticking: \",nb_stays,\" nb won when sticking: \",nb_won_sticking,\"nb switching:\",nb_switches,\" nb won when switching:\",nb_won_switching)    \n",
    "    repeat = input(\"Another game?   Answer by (y/n) + enter\\n\").upper()\n",
    "print(\"Game over\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
